<template>
	<span class="permission" v-if="hasPermission">
		<slot></slot>
	</span>
</template>
<script>
	/*
	* permissionButton 按钮权限控制
	* permissionKey {String}  按钮权限值
	*/
	export default {
		name: 'layer',
		props: {
			permissionKey: {
				type: String,
				default() {
					return ''
				}
			}
		},
		computed: {
			// 根据路由获取当前页面的按钮权限信息
			buttonPermissionList() {
				if (this.$store.getters.userMenus && !this.$store.getters.userMenus.length) return []
				let _path = this.$route.path
				let _item = this.$store.getters.userMenus.find(item => {
					if (_path.indexOf('/system/org') > -1 || _path.indexOf('/system/user') > -1) {
						return _path.indexOf(item.router) > -1
					}
					else {
						return this.$route.path == item.router
					}
				})
				if (_item && !_item.id) return []
				let _permissions = []
				this.$store.getters.userMenus.forEach(item => {
					if (item.parentId == _item.id) {
						_permissions.push(item)
					}
				})
				return _permissions
			},
			hasPermission() {
				if (this.buttonPermissionList.length) {
					let _flag = false
					for (let i = 0, len = this.buttonPermissionList.length; i < len; i++) {
						if (this.buttonPermissionList[i].permissionKey === this.permissionKey) {
							_flag = true
							break
						}
					}
					return _flag
				}
				return false
			}

		}
	};
</script>